<?php


abstract class BaseResidencia extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $cp_residencia;


	
	protected $cf_estudiante;


	
	protected $cf_estado;


	
	protected $cf_municipio;


	
	protected $cf_ciudad;


	
	protected $direccion;


	
	protected $habitacion;


	
	protected $mensualidad;


	
	protected $telefono;


	
	protected $tipo_residencia;


	
	protected $estatus;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getCpResidencia()
	{

		return $this->cp_residencia;
	}

	
	public function getCfEstudiante()
	{

		return $this->cf_estudiante;
	}

	
	public function getCfEstado()
	{

		return $this->cf_estado;
	}

	
	public function getCfMunicipio()
	{

		return $this->cf_municipio;
	}

	
	public function getCfCiudad()
	{

		return $this->cf_ciudad;
	}

	
	public function getDireccion()
	{

		return $this->direccion;
	}

	
	public function getHabitacion()
	{

		return $this->habitacion;
	}

	
	public function getMensualidad()
	{

		return $this->mensualidad;
	}

	
	public function getTelefono()
	{

		return $this->telefono;
	}

	
	public function getTipoResidencia()
	{

		return $this->tipo_residencia;
	}

	
	public function getEstatus()
	{

		return $this->estatus;
	}

	
	public function setCpResidencia($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cp_residencia !== $v) {
			$this->cp_residencia = $v;
			$this->modifiedColumns[] = ResidenciaPeer::CP_RESIDENCIA;
		}

	} 
	
	public function setCfEstudiante($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_estudiante !== $v) {
			$this->cf_estudiante = $v;
			$this->modifiedColumns[] = ResidenciaPeer::CF_ESTUDIANTE;
		}

	} 
	
	public function setCfEstado($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_estado !== $v) {
			$this->cf_estado = $v;
			$this->modifiedColumns[] = ResidenciaPeer::CF_ESTADO;
		}

	} 
	
	public function setCfMunicipio($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_municipio !== $v) {
			$this->cf_municipio = $v;
			$this->modifiedColumns[] = ResidenciaPeer::CF_MUNICIPIO;
		}

	} 
	
	public function setCfCiudad($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_ciudad !== $v) {
			$this->cf_ciudad = $v;
			$this->modifiedColumns[] = ResidenciaPeer::CF_CIUDAD;
		}

	} 
	
	public function setDireccion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->direccion !== $v) {
			$this->direccion = $v;
			$this->modifiedColumns[] = ResidenciaPeer::DIRECCION;
		}

	} 
	
	public function setHabitacion($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->habitacion !== $v) {
			$this->habitacion = $v;
			$this->modifiedColumns[] = ResidenciaPeer::HABITACION;
		}

	} 
	
	public function setMensualidad($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->mensualidad !== $v) {
			$this->mensualidad = $v;
			$this->modifiedColumns[] = ResidenciaPeer::MENSUALIDAD;
		}

	} 
	
	public function setTelefono($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->telefono !== $v) {
			$this->telefono = $v;
			$this->modifiedColumns[] = ResidenciaPeer::TELEFONO;
		}

	} 
	
	public function setTipoResidencia($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->tipo_residencia !== $v) {
			$this->tipo_residencia = $v;
			$this->modifiedColumns[] = ResidenciaPeer::TIPO_RESIDENCIA;
		}

	} 
	
	public function setEstatus($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->estatus !== $v) {
			$this->estatus = $v;
			$this->modifiedColumns[] = ResidenciaPeer::ESTATUS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->cp_residencia = $rs->getString($startcol + 0);

			$this->cf_estudiante = $rs->getString($startcol + 1);

			$this->cf_estado = $rs->getString($startcol + 2);

			$this->cf_municipio = $rs->getString($startcol + 3);

			$this->cf_ciudad = $rs->getString($startcol + 4);

			$this->direccion = $rs->getString($startcol + 5);

			$this->habitacion = $rs->getString($startcol + 6);

			$this->mensualidad = $rs->getInt($startcol + 7);

			$this->telefono = $rs->getString($startcol + 8);

			$this->tipo_residencia = $rs->getString($startcol + 9);

			$this->estatus = $rs->getString($startcol + 10);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 11; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Residencia object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ResidenciaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			ResidenciaPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ResidenciaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ResidenciaPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setCpResidencia($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += ResidenciaPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = ResidenciaPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ResidenciaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCpResidencia();
				break;
			case 1:
				return $this->getCfEstudiante();
				break;
			case 2:
				return $this->getCfEstado();
				break;
			case 3:
				return $this->getCfMunicipio();
				break;
			case 4:
				return $this->getCfCiudad();
				break;
			case 5:
				return $this->getDireccion();
				break;
			case 6:
				return $this->getHabitacion();
				break;
			case 7:
				return $this->getMensualidad();
				break;
			case 8:
				return $this->getTelefono();
				break;
			case 9:
				return $this->getTipoResidencia();
				break;
			case 10:
				return $this->getEstatus();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ResidenciaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCpResidencia(),
			$keys[1] => $this->getCfEstudiante(),
			$keys[2] => $this->getCfEstado(),
			$keys[3] => $this->getCfMunicipio(),
			$keys[4] => $this->getCfCiudad(),
			$keys[5] => $this->getDireccion(),
			$keys[6] => $this->getHabitacion(),
			$keys[7] => $this->getMensualidad(),
			$keys[8] => $this->getTelefono(),
			$keys[9] => $this->getTipoResidencia(),
			$keys[10] => $this->getEstatus(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ResidenciaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCpResidencia($value);
				break;
			case 1:
				$this->setCfEstudiante($value);
				break;
			case 2:
				$this->setCfEstado($value);
				break;
			case 3:
				$this->setCfMunicipio($value);
				break;
			case 4:
				$this->setCfCiudad($value);
				break;
			case 5:
				$this->setDireccion($value);
				break;
			case 6:
				$this->setHabitacion($value);
				break;
			case 7:
				$this->setMensualidad($value);
				break;
			case 8:
				$this->setTelefono($value);
				break;
			case 9:
				$this->setTipoResidencia($value);
				break;
			case 10:
				$this->setEstatus($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ResidenciaPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setCpResidencia($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCfEstudiante($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCfEstado($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCfMunicipio($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCfCiudad($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setDireccion($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setHabitacion($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setMensualidad($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTelefono($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setTipoResidencia($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setEstatus($arr[$keys[10]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ResidenciaPeer::DATABASE_NAME);

		if ($this->isColumnModified(ResidenciaPeer::CP_RESIDENCIA)) $criteria->add(ResidenciaPeer::CP_RESIDENCIA, $this->cp_residencia);
		if ($this->isColumnModified(ResidenciaPeer::CF_ESTUDIANTE)) $criteria->add(ResidenciaPeer::CF_ESTUDIANTE, $this->cf_estudiante);
		if ($this->isColumnModified(ResidenciaPeer::CF_ESTADO)) $criteria->add(ResidenciaPeer::CF_ESTADO, $this->cf_estado);
		if ($this->isColumnModified(ResidenciaPeer::CF_MUNICIPIO)) $criteria->add(ResidenciaPeer::CF_MUNICIPIO, $this->cf_municipio);
		if ($this->isColumnModified(ResidenciaPeer::CF_CIUDAD)) $criteria->add(ResidenciaPeer::CF_CIUDAD, $this->cf_ciudad);
		if ($this->isColumnModified(ResidenciaPeer::DIRECCION)) $criteria->add(ResidenciaPeer::DIRECCION, $this->direccion);
		if ($this->isColumnModified(ResidenciaPeer::HABITACION)) $criteria->add(ResidenciaPeer::HABITACION, $this->habitacion);
		if ($this->isColumnModified(ResidenciaPeer::MENSUALIDAD)) $criteria->add(ResidenciaPeer::MENSUALIDAD, $this->mensualidad);
		if ($this->isColumnModified(ResidenciaPeer::TELEFONO)) $criteria->add(ResidenciaPeer::TELEFONO, $this->telefono);
		if ($this->isColumnModified(ResidenciaPeer::TIPO_RESIDENCIA)) $criteria->add(ResidenciaPeer::TIPO_RESIDENCIA, $this->tipo_residencia);
		if ($this->isColumnModified(ResidenciaPeer::ESTATUS)) $criteria->add(ResidenciaPeer::ESTATUS, $this->estatus);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ResidenciaPeer::DATABASE_NAME);

		$criteria->add(ResidenciaPeer::CP_RESIDENCIA, $this->cp_residencia);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getCpResidencia();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setCpResidencia($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCfEstudiante($this->cf_estudiante);

		$copyObj->setCfEstado($this->cf_estado);

		$copyObj->setCfMunicipio($this->cf_municipio);

		$copyObj->setCfCiudad($this->cf_ciudad);

		$copyObj->setDireccion($this->direccion);

		$copyObj->setHabitacion($this->habitacion);

		$copyObj->setMensualidad($this->mensualidad);

		$copyObj->setTelefono($this->telefono);

		$copyObj->setTipoResidencia($this->tipo_residencia);

		$copyObj->setEstatus($this->estatus);


		$copyObj->setNew(true);

		$copyObj->setCpResidencia(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ResidenciaPeer();
		}
		return self::$peer;
	}

} 